<template>
  <div class="app-main">
    <div class="divHead">
      <el-row :gutter="20">
        <el-col :span="6">
          <div class="grid-content bg-purple">仓库名称</div>
          <div class="el-input el-input--medium">
            <el-input
              v-model="frompage.areaName"
              placeholder="请输入内容"
              autocomplete="off"
            ></el-input>
          </div>
        </el-col>
        <el-col :span="6">
          <div class="grid-content bg-purple">库区名称</div>
          <div class="el-input el-input--medium">
            <el-input
              v-model="frompage.name"
              placeholder="请输入内容"
              autocomplete="off"
            ></el-input>
          </div>
        </el-col>
        <el-col :span="6">
          <div class="grid-content bg-purple">仓库状态</div>
          <div></div>
          <el-select
            v-model="frompage.status"
            placeholder="请选择"
            class="el-input el-input--medium el-input--suffix"
          >
            <el-option
              v-for="item in options"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            >
            </el-option>
          </el-select>
        </el-col>
        <div class="divButton">
          <button class="minorImportantButton btnSearch" @click="query">
            搜索
          </button>
          <button class="unimportanceButton" @click="reset">重置</button>
        </div>
      </el-row>
    </div>
    <div class="divContent">
      <button class="importantButton btnAdd" @click="$router.push('/location/details/'+null)">新增仓库</button>
      <div class="twobutton">
        <button @click="updownexcle">下载库区</button>
        <button @click="importexcle">导入库区信息</button>
      </div>
     <div v-if="isshow" class="emptyTip">
       <div class="img">

       </div>
         <p>暂无库区</p>
     </div>
      <div v-else>
        <el-table :data="tableData?.records" stripe style="width: 100%">
          <el-table-column type="index" label="序号" width="100">
          </el-table-column>
          <el-table-column prop="warehouseName" label="所属仓库">
          </el-table-column>
          <el-table-column prop="areaCode" label="库区编号" width="100">
          </el-table-column>
          <el-table-column prop="areaName" label="库区名称" width="100">
          </el-table-column>
          <el-table-column prop="code" label="库位编号" width="100">
          </el-table-column>
           <el-table-column prop="name" label="库位名称" width="100">
          </el-table-column>

          <el-table-column prop="type" label="温度类型">
            <template slot-scope="scope">
              <span>{{
                scope.row.temperatureType === "CW"
                  ? "常温"
                  : scope.row.temperatureType === "LC"
                  ? "冷藏"
                  : "恒温"
              }}</span>
            </template>
          </el-table-column>
          <el-table-column prop="bearingType" label="承重类型">
            <template slot-scope="scope">
              <span>{{
                scope.row.bearingType === "ZX" ? "重型" : "轻型"
              }}</span>
            </template>
          </el-table-column>
          <el-table-column prop="useType" label="用途属性">
            <template slot-scope="scope">
              <span>{{
                scope.row.useType === "RKHCQ"
                  ? "入库缓存区"
                  : scope.row.useType === "CKHCQ"
                  ? "出库缓存区"
                  : scope.row.useType === "CCQ"
                  ? "存储区"
                  : scope.row.useType === "FJQ"
                  ? "分拣区"
                  : "质检区"
              }}</span>
            </template>
          </el-table-column>
          <el-table-column prop="status" label="停用状态">
            <template slot-scope="scope">
              <span>{{ scope.row.status === 0 ? "停用" : "启用" }}</span>
            </template>
          </el-table-column>

          <el-table-column prop="maxNum" label="承载上线"> </el-table-column>

          <el-table-column prop="updateTime" label="更新时间" width="180px">
          </el-table-column>
          <el-table-column prop="address" label="操作" width="180px">
            <template slot-scope="scope">
              <span style="color: #ffb200" @click="edit(scope.row)">编辑</span>&nbsp;&nbsp;
              <span style="color: #ffb200" @click="puteare(scope.row)">{{
                scope.row.status === 1 ? "停用" : "启用"
              }}</span
              >&nbsp;&nbsp;
              <span style="color: #ffb200" @click="del(scope.row.id)"
                >删除</span
              >
            </template>
          </el-table-column>
        </el-table>
      </div>
    </div>
    <PageTool
      :total="tableData.total"
      :paginationPage="frompage.current"
      :paginationPagesize="frompage.size"
      @pageChange="pageChangeFn"
      @pageSizeChange="pageSizeChangeFn"
    />
    <el-dialog
  title="提示"
  :visible.sync="dialogVisible"
  width="30%"
  >
<el-upload
  class="upload-demo"
  drag
  action="https://jsonplaceholder.typicode.com/posts/"
  multiple>
  <i class="el-icon-upload"></i>
  <div class="el-upload__text">将文件拖到此处，或<em>点击上传</em></div>
  <div class="el-upload__tip" slot="tip">只能上传jpg/png文件，且不超过500kb</div>
</el-upload>
  <span slot="footer" class="dialog-footer">
    <el-button @click="dialogVisible = false">取 消</el-button>
    <el-button type="primary" @click="ok">确 定</el-button>
  </span>
</el-dialog>
  </div>
</template>

<script>
import PageTool from '@/compont/PageTool.vue'
import { getKqList, delKq, editKq, excle, importexcle } from '@/api/location'
export default {
  components: {
    PageTool
  },
  data () {
    return {
      dialogVisible: false,
      isshow: true,
      tableData: {},
      frompage: {
        areaName: '',
        name: '',
        status: null,
        current: 1,
        size: 10
      },
      options: [
        {
          value: null,
          label: '全部'
        },
        {
          value: '1',
          label: '启用'
        },
        {
          value: '0',
          label: '禁用'
        }
      ]
    }
  },
  created () {
    this.arealist()
  },
  methods: {
    ok () {
      importexcle()
    },
    importexcle () {
      this.dialogVisible = true
    },
    async   updownexcle () {
      const res = await excle()
      this.$downloadFile(res, '员工表')
    },
    async  puteare (row) {
      await this.$confirm(`确定要${row.status === 0 ? '启用' : '停用'}:, 测试${row.name

}吗?`, {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.$message({
          type: 'success',
          message: '操作成功!'
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        })
      })
      await editKq({
        id: row.id,
        status: row.status === 1 ? 0 : 1
      })
      this.arealist()
    },
    async del (id) {
      await delKq(id)
      this.arealist()
      this.$message.success('删除成功')
    },
    async arealist () {
      const { data } = await getKqList(this.frompage)
      this.tableData = data
      this.isshow = !data.records.length
    },
    // 编辑跳转
    edit (row) {
      this.$router.push('/location/details/' + row.id)
    },
    // 查询有bug
    async query () {
      this.arealist()
    },
    // 重置表单
    reset () {
      this.frompage.areaName = null
      this.frompage.name = null
      this.frompage.status = null
    },
    pageChangeFn (page) {
      this.frompage.current = page
      this.arealist()
    },
    pageSizeChangeFn (size) {
      this.frompage.size = size
      this.arealist()
    }
  }
}
</script>

<style lang="less" scoped>
.emptyTip {
    border-top: 1px solid #f5efee;
    padding: 100px 0;
    margin: 0 auto;
    color: #b5abab;
    font-size: 14px;
    text-align: center;

}
.app-main {
  min-height: calc(100vh - 50px);
  background-color: #fdfafa;
  width: 100%;
  position: relative;
  overflow: hidden;
}
.divContent {
  margin-top: 15px;
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 0 6px 0 rgb(144 142 142 / 17%);
}
.divContent .btnAdd {
  margin-left: 30px;
  margin-top: 20px;
  margin-bottom: 20px;
}
.importantButton {
  background: #00be76;
  color: #fff;
  height: 40px;
  border-radius: 20px;
  border: 0;
  font-size: 14px;
  font-family: PingFangSC, PingFangSC-Medium;
  font-weight: 500;
  text-align: center;
  line-height: 40px;
  padding-left: 26px;
  padding-right: 26px;
  cursor: pointer;
  outline: 0;
}
.divHead {
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 0 6px 0 rgb(144 142 142 / 17%);
  padding: 30px;
}
/deep/.grid-content {
  margin-bottom: 10px;
  height: 18px;
  font-size: 12px;
  color: #887e7e;
  font-size: 12px;
  font-family: PingFangSC, PingFangSC-Medium;
  font-weight: 500;
}
/deep/.el-input--medium .el-input__inner {
  height: 40px;
  line-height: 40px;
  border: 1px solid #f8f5f5;
  background: #f8f5f5;
  border-radius: 6px;
}

/deep/.el-input__inner {
  padding-left: 12px;
  padding-right: 12px;
  box-sizing: border-box;
  color: #1f2d3d;
  display: inline-block;
  font-size: inherit;
  outline: none;
  padding: 0 15px;
  transition: border-color 0.2s cubic-bezier(0.645, 0.045, 0.355, 1);
  width: 100%;
}

.divButton {
  float: right;
}
.divButton .btnSearch {
  margin-right: 20px;
  margin-top: 25px;
}
.minorImportantButton {
  background: #ffb200;
  color: #332929;
  height: 40px;
  border-radius: 20px;
  border: 0;
  font-size: 14px;
  font-family: PingFangSC, PingFangSC-Medium;
  font-weight: 500;
  text-align: center;
  line-height: 40px;
  padding-left: 26px;
  padding-right: 26px;
  cursor: pointer;
  outline: 0;
}
.unimportanceButton {
  background: #f8f5f5;
  color: #332929;
}
.unimportanceButton {
  height: 40px;
  border-radius: 20px;
  border: 0;
  font-size: 14px;
  font-family: PingFangSC, PingFangSC-Medium;
  font-weight: 500;
  text-align: center;
  line-height: 40px;
  padding-left: 26px;
  padding-right: 26px;
  cursor: pointer;
  outline: 0;
}

.twobutton {
  float: right;
  margin-top: 15px;
  margin-right: 25px;
}
.twobutton button {
  height: 40px;
  border-radius: 20px;
  border: 0;
  font-size: 14px;
  font-family: PingFangSC, PingFangSC-Medium;
  font-weight: 500;
  text-align: center;
  line-height: 40px;
  padding-left: 26px;
  padding-right: 26px;
  cursor: pointer;
  outline: 0;
  margin-left: 15px;
  width: 150px;
}
.twobutton button:hover {
  background-color: #ffb200;
}
.img {
  width: 160px;
  height: 160px;
  display: inline-block;
  background: url("http://www-wms-java.itheima.net/img/empty.4300e933.png")
    no-repeat;
  background-size: contain;
}
span{
  cursor: pointer;
}
</style>
